package com.xneure.function.processor;

import com.xneure.code.exception.FunctionException;
import com.xneure.function.enums.TokenType;
import com.xneure.function.node.Token;

public class FunctionHandler extends TokenProcessor{
	public FunctionHandler(TokenProcessor parent){
		super(parent);
	}

	@Override
	public void processor(Token currToken,Token beforeToken){
		if(null != next){
			next.processor(currToken,beforeToken);
		}else{
			if(currToken.type == TokenType.RIGHT_BRACKETS){
				if(null == parent){
					throw new FunctionException(String.format("位置 %1s:%2s 缺失 （  ",currToken.line,currToken.beginPoint));
				}
				parent.next = null;
			}else{
				if(currToken.type == TokenType.LEFT_BRACKETS){
					next = new BracketsHandler(this);
				}else{
					next = new FunctionHandler(this);
					
				}
				next.parent = this;
			}
		}
	}

	@Override
	public void end(){
		throw new FunctionException("结束时缺失 )  ");
	}
}
